package com.yungu.swift.api.route.v1.passenger;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.api.base.BaseApi;
import com.yungu.swift.assets.passenger.service.PassengerService;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.order.service.OrderFareService;
import com.yungu.swift.utils.MapUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 描述：
 *
 * @author Zerrion
 * @Time 2018/2/28
 */
@Controller
@RequestMapping(value = "/api/v1/passenger")
@Api(value = "【乘客】【订单】【出租车】乘客出租车订单接口", tags = "乘客出租车订单相关操作")
public class TaxiOrderApi extends BaseApi {

    @Reference
    private PassengerService passengerService;
    @Reference
    private OrderFareService orderFareService;


    @RequestMapping(value = {"/token/order/fareItems"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "乘客订单费用详情接口", notes = "费用详情", response = ResponseData.class)
    public ResponseData<Map<String, Object>> fareItems(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "orderUuid", value = "订单uuid", required = true) @RequestParam String orderUuid,
            @ApiParam(name = "couponUuid", value = "优惠券uuid，没有更换优惠券时，该值放空") @RequestParam(required = false) String couponUuid,
            HttpServletRequest request) {

        //获取用户的信息
        Map<String, Object> map = MapUtils.build();
        map.put("uuid", getUserUid(request));
        if (passengerService.get(map).getData() == null) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "获取用户信息错误");
        }
        return orderFareService.getFareItems(orderUuid, couponUuid, 1);
    }
}
